package com.supersoul.myself.util;

import com.supersoul.myself.enums.ServiceEnum;
import lombok.Data;

@Data
public class R<T> {

    private int code = 0;
    private String message = "操作成功";
    private T data;

    public static R success() {
        return new R();
    }

    public static <T> R<T> success(T data) {
        R<T> r = new R<T>();
        r.setData(data);
        return r;
    }

    public static R failed() {
        R r = new R();
        r.setCode(-1);
        r.setMessage("操作失败");
        return r;
    }

    public static R failed(String message) {
        R r = new R();
        r.setCode(-1);
        r.setMessage(message);
        return r;
    }

    public static R failed(ServiceEnum serviceEnum) {
        R r = new R();
        r.setCode(serviceEnum.getCode());
        r.setMessage(serviceEnum.getDesc());
        return r;
    }
}
